class Category < ActiveRecord::Base
	
	acts_as_taggable	

	has_many :articles
	has_many :childs, :class_name=>"Category", :foreign_key=>"category_id", :dependent=>:destroy
	belongs_to :parent, :class_name=>"Category", :foreign_key=>"category_id"

	named_scope :root, :conditions => {:category_id => nil}

	validates_presence_of :name

	def to_param
		"#{self.id}-#{self.slug}"
	end

	def before_save
		self.slug = self.name.parameterize if self.slug.blank?
	end
end
